<!DOCTYPE html>
<include file="Public:header" title="服务列表"/>
<body>
<div class="table-responsive packages">
    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
        <thead>
        <tr>
            <th width='45px' class="center">ID</th>
            <th>服务ip</th>
            <th>服务器账户</th>
            <th>服务器初始密码</th>
            <th width="120px">服务器类型</th>
            <th width="120px">联系qq</th>
            <th width="120px">联系手机</th>
            <th width="120px">开始时间</th>
            <th width="120px">结束时间</th>
        </tr>
        </thead>
        <tbody class="packageslist">
        <foreach name="servers_list" item="row">
            <tr class="packages_{$row.id}">
                <td class="center">{$row.id}</td>
                <td>{$row.ip}</td>
                <td>{$row.account}</td>
                <td>{$row.initial_password}</td>
                <td style="width: 150px">{$row.servers_type|seventype}</td>
                <td>{$row.qq}</td>
                <td>{$row.mobile}</td>
                <td><notempty name="row.start_time">{$row.start_time|date="m-d H:i",###}</notempty></td>
                <td><notempty name="row.end_time">{$row.end_time|date="m-d H:i",###}</notempty></td>
            </tr>
        </foreach>
        </tbody>
    </table>
</div>
<style>
    .packages .createpackages{
        margin-left: 20px;
        font-size: 20px;
        color: #002eb3;
        cursor: pointer;
    }
</style>
<script src="__PUBLIC__/plugins/layer/layer.js"></script>
<script>
    function createpackages() {
         var htm = '<tr class="packages_add">';
         htm += '<td>-</td>';
         htm += ' <td><input type="text" class="packagesname" value="" ></td>';
         htm += '<td><input type="text" class="packagprice"  value="" >元</td>';
         htm += '<td><input type="text" class="packagord" value="0" ></td>';
         htm += '<td id="packagis_check"><a> 是</a></td>';
         htm += '<td class="action-buttons">';
         htm += '<a class="packageoperation"><span class="packagesedit" onclick="packagesadd(this)" style="color: #00b33b">保存</span></a>';
         htm += '</td>';
         htm += '</tr>';
        $(".packageslist").append(htm);
    }

    function packagesadd(obj) {
      var  packagesname = $(obj).parent().parent().parent().find('.packagesname').val();
      var  packagprice = $(obj).parent().parent().parent().find('.packagprice').val();
      var  packagord = $(obj).parent().parent().parent().find('.packagord').val();
      var  service_id = $('#service_id').val();
        $.post("{:U('Service/create_packages')}", {
            pid: service_id,
            name: packagesname,
            price: packagprice,
            ord: packagord,
        }, function(data) {
            if(data.code == 200 ){
                layer.open({
                    content: '添加成功'
                    ,skin: 'msg'
                    ,time: 3000//2秒后自动关闭
                    ,end: function () {
                        window.location.reload()
                    }
                });
            }else{
                layer.alert('添加失败', {
                    icon: 2,
                    skin: 'layer-ext-moon'
                })
            }
        })
    }

    function packagesdel() {
        var packages_add_count = $(".packages_add").length;
        var packages_add_count = packages_add_count + 1;
        $('.packageslist').children(".packages_add:last").remove();

    }
    function packagesedit(obj,id,service_id) {
        $(".packages_"+id).find('input').removeAttr('readonly');
        var  htm = '<span class="packagesedit" onclick="packagessave(this,'+id+','+service_id+')" style="color: #00b33b">保存</span>';
        $(".packageoperation_"+id).html(htm);
    }
    
    function packagessave(obj,id,service_id) {
        var packagesname = $('.packagesname_'+id).val();
        var packagprice = $('.packagprice_'+id).val();
        var packagord = $('.packagord_'+id).val();
        var  service_id = $('#service_id').val();
        $.post("{:U('Service/edit_packages')}", {
            pid: service_id,
            name: packagesname,
            price: packagprice,
            ord: packagord,
            id: id,
        }, function(data) {
            if( data.code == 200 ){
                layer.open({
                    content: '修改成功'
                    ,skin: 'msg'
                    ,time: 3000//2秒后自动关闭
                    ,end: function () {
                        window.location.reload()
                    }
                });
            }else{
                layer.alert('修改失败', {
                    icon: 2,
                    skin: 'layer-ext-moon'
                })
            }
        })
    }
    function isyes(id, table, field) {
        $.post("{:U('Ajax/yes')}", {
            id: id,
            table: table,
            field: field
        }, function(data) {
            if (data == "是") {
                $('#' + field + '_' + id).html("<a onclick=isyes(" + id + ",'" + table + "','" + field + "')>" + data + "</a>");
            } else {
                $('#' + field + '_' + id).html("<a onclick=isyes(" + id + ",'" + table + "','" + field + "')><span style='color:red'>" + data + "</span></a>");
            }
        })
    }
</script>
</body>
</html>